home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Error Dialogs / ErrorAlert.sit / ErrorCheck.h < prev    next >
Text File  |  1994-02-12  |  5KB  |  113 lines

  1. //////////////////////////////////////////////////////////////////////
  2. //
  3. //  ErrorCheck.h
  4. //
  5. //  This is the header file for ErrorCheck.cp.  Using this code it is possible
  6. //  to report a wide variety of messages to the user, and either display a
  7. //  simple Alert or a more sophisticated debugging alert.
  8. //
  9. //  Related Files:  ErrorCheck.rsrc contains the minimum number of resources to
  10. //  operate ErrorCheck.  It also provides a list of standardized strings to
  11. //  output typical messages to the user.
  12. //
  13. /////////////////////////////////////////////////////////////////////
  14.  
  15.  
  16. #ifndef ErrorCheck
  17. #define ErrorCheck
  18.  
  19. // When the following #define is included, other modules are expected to implement
  20. // additional error checking code that takes extra time, but stops bugs dead in
  21. // their tracks.  In addition, the program drops right into the local debugger
  22. // using DebugStr, instead of bothering to put up a dialog box.....  Among other
  23. // things, this allows us to include special debugging strings in our code in a
  24. // transparent and extendable way.
  25.  
  26. // When compiling final versions (or testing for performance) comment it out
  27.  
  28. #define SANITY_CHECK
  29.  
  30. //  String constants used in ParamText
  31. const Str255 kEmptyString = "\p";
  32.  
  33. // This one gets used if the program is unable to obtain a string from the STR#
  34. // resource.  Since this is hard coded, this is obviously a last ditch chance to
  35. // put something up!
  36. const Str255 kBogusError = "\pUnrecoverable Error";
  37.  
  38. // Error strings are combined into categories, each category being a separate
  39. // STR# resource.  This header creates a set of generic errors, usually used to flag
  40. // conditions like older ROMs or System Software.  Each major object, module, or
  41. // subsection should define its own 'STR#' resource to handle errors it flags.
  42. //
  43. // NOTE: Some of these erros are very generic and should be overridden with a more
  44. // specific error string whenever possible.
  45.     
  46. const short rDefaultStrings = 5000;
  47.                                     
  48. const short errOSErr = 1;            // This one should probably never be used for a real error
  49. const short errWimpyROMs = 2;        // Used if ROMs are older than the 128K Mac Plus ROMs
  50. const short errNeedSystem6 = 3;
  51. const short errNeedSystem607 = 4;
  52. const short errNeedSystem7 = 5;
  53. const short errWeirdSystem = 6;        // right minimum system, but missing something that
  54.                                     // should be there
  55. const short errNoMBAR = 7;            
  56. const short errNoMENU    = 8;            
  57. const short errNoCNTL = 9;            
  58. const short errNoWIND    = 10;
  59.  
  60. // 'ALRT' constants (DITLs will have the same resource ID)
  61. const short rDeathAlert = 5000;            // Alert resource for program crash
  62. const short rNotDeadYetAlert = 5001;    // Alert resource for non-fatal error.
  63.  
  64.  
  65. //  Function Declarations
  66. //  In order to keep the interface flexible, I used overloaded functions.  The first function
  67. //  definition is the one that most final program error routines should call -- one that grabs
  68. //  a string from a resource and displays it.
  69.  
  70. //  The others are primarily intended for debugging, but are included even if compiled in
  71. //  the final version.  They could be used when the program needs to present a customized
  72. //  string that it builds beforehand.
  73.  
  74. //  All routines pass in a Boolean that tells whether or not this is a fatal eror.  
  75.  
  76. extern void ErrorAlert (short ErrorStringsList,
  77.                         short ErrorStringNumber,
  78.                         Boolean DeadOnArrival);
  79.  
  80. // Allows the user to specify a specific string.  Great if you need to build the string
  81. // beforehand or if you just want to include a DebugStr.  Okay, I guess you could just
  82. // call DebugStr, but this way all errors have a consistent interface.
  83.  
  84. extern void ErrorAlert (Str255 ErrorMessage,
  85.                         Boolean DeadOnArrival);                        
  86.  
  87. // This one combines a string and a short, useful for giving a numerical
  88. // error code, such as an OSErr.
  89. extern void ErrorAlert (Str255 ErrorMessage,
  90.                         short ErrorNumber,
  91.                         Boolean DeadOnArrival);
  92.                         
  93. // This last one combines references to a string contained in the resource fork with
  94. // a number.  Usually, this is used to report OSErrs.
  95.  
  96. extern void ErrorAlert (short ErrorStringsList,
  97.                         short ErrorStringNumber,
  98.                         short ErrorNumber, 
  99.                         Boolean DeadOnArrival);
  100.  
  101. // These routines are used for simple sanity checking -- since they always call ErrorAlert
  102. // without doing anything nice, they aren't suitable for robust error checking code that
  103. // should exit gracefully.  All of them return the actual error number returned by the
  104. // system.
  105.  
  106. // MemoryErrCheck and ResourceErrCheck check for the additional case of a NIL pointer.
  107. // Because MemoryErrCheck can be used on Ptrs or Handles, we use overloaded functions again.
  108. extern void OSErrCheck (OSErr err);
  109. extern void MemoryErrCheck (Handle err);
  110. extern void MemoryErrCheck (Ptr err);
  111. extern void ResourceErrCheck (Handle err);
  112.  
  113. #endif ErrorCheck